<template>
  <view>
<!--    <my-search :bgcolor="'pink'" :radius="13"/> -->
        <my-search @click=handlerSearch />
      <view class="scroll-container">
        
            <scroll-view scroll-y="true" class="scroll-left" :style="{height:syninfo+'px'}"> 
            <block v-for="(item,c) in cateList" :key="c">
              <view :class="['scroll-let-item',c===active?'active':''] " @click="handlerCate(c)">{{item.cat_name}}</view>
            </block>            
            </scroll-view>

    <scroll-view scroll-y="true"class="scroll-right" :style="{height:syninfo+'px'}" :scroll-top="scrollTop">
      <block v-for="(item,i) in cateChildren" :key="i" v-if="item.children.length">
        <view class="cate-title">/{{item.cat_name}}/</view>
        <view class="cate-list-image">
          <view class="cateImage" v-for="(item2,p) in item.children" @click="handlerCatetext(item2.cat_id)">
                  <image :src="item2.cat_icon" mode="heightFix"></image>
                  <text class="cateText">{{item2.cat_name}}</text>
        </view>
        </view>
        
        </block>
    </scroll-view>
      </view>
  </view>
</template>

<script>
    import badgeMix from "@/mixins/tabbar-badge.js"
  export default {
          mixins:[badgeMix],
    data() {
      return {
        syninfo:'',
        cateList:[],
        active:0,
        cateChildren:[],
        scrollTop:0
      };
    },
    onLoad() {
      this.getCateList()
      this.syninfo=uni.getSystemInfoSync().windowHeight-50
      console.log(this.syninfo)
    },
    methods:{
      handlerSearch(){
       uni.navigateTo({
         url:"/subpkg/search/search"
       })
      },
      handlerCatetext(id){
        uni.navigateTo({
          url:`/subpkg/goods_list/goods_list?cid=${id}`
        })
      },
      handlerCate(c){
        this.active=c
        this.cateChildren=this.cateList[c].children
        this.scrollTop=this.scrollTop===0?1:0
      },
    async getCateList(){
       const {data:res}=await uni.$http.get("/api/public/v1/categories")
      
        if(res.meta.status!==200){
          return uni.$showmag("数据请求失败",1000,"none")
        }
         this.cateChildren=res.message[0].children
        this.cateList=res.message
        uni.$showmag('数据请求成功',2000,"none")
      }
    }
  }
</script>

<style lang="scss">
.scroll-container{
  display: flex;
  
  .scroll-left{
    width: 120px;
    // flex-shrink:8
    .scroll-let-item{
    text-align: center;
      font-size: 12px;
      background-color: #F7F7F7;
      line-height: 60px;
    &.active{
      background-color: #FFFFFF;
      position: relative;
     &::before{
       content: " ";
       display: block;
       width: 3px;
       height: 30px;
       background-color: #c00000;
       position: absolute;
       top: 50%;
       transform: translateY(-50%);
     } 
    }
    }

  }
}
.cate-title{
  font-size: 12px;
  font-weight: bold;
  text-align:center;
  padding: 15px 0;
}

.cate-list-image{
  display: flex;
  justify-content:space-between;
  flex-wrap: wrap;
  padding: 0 10px;
  .cateImage{
    display: flex;
    flex-direction: column;
    width: 80px;
    height: 100px;
    // box-shadow:0px 0px 5px #888888;
    margin: 5px 0;
 
      // margin-top: 10px;
    image{ 
      
      width: 100%;
      height: 100%;
      margin: 10px auto;
      
    }
    text{
      font-size: 12px;
      text-align: center;
    
    }
  }
}


</style>
